package cdworks.lifecounter;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class LCDbHelper extends SQLiteOpenHelper{
	
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "LC.db";
    
    private static final String TABLE_UPDATE = "updatedb";
    
    private static final String TEXT_TYPE = " TEXT";
    private static final String COMMA_SEP = ",";
    private static final String SQL_CREATE_ENTRY1 =
        "CREATE TABLE " + LCContract.LCEntry.TABLE_NAME + " (" +
        		LCContract.LCEntry._ID + " integer PRIMARY KEY AUTOINCREMENT, " +
        		LCContract.LCEntry.COLUMN_NAME_TYPE + TEXT_TYPE + COMMA_SEP +
        		LCContract.LCEntry.COLUMN_NAME_AMOUNT + TEXT_TYPE + COMMA_SEP +
        		LCContract.LCEntry.COLUMN_NAME_TIME + TEXT_TYPE + COMMA_SEP +
        		LCContract.LCEntry.COLUMN_NAME_SIGN + TEXT_TYPE +
        " )";
    private static final String SQL_CREATE_ENTRY2 =
            "CREATE TABLE " + LCContract.LCInEntry.TABLE_NAME + " (" +
            		LCContract.LCInEntry._ID + " integer PRIMARY KEY AUTOINCREMENT, " +
            		LCContract.LCInEntry.COLUMN_NAME_TYPE + TEXT_TYPE + 
            " )";
    
    //private static final String SQL_DELETE_ENTRIES =
    	    //"DROP TABLE IF EXISTS " + TABLE_NAME_ENTRIES;
    
    public LCDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(SQL_CREATE_ENTRY1);
		db.execSQL(SQL_CREATE_ENTRY2);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//db.execSQL(SQL_DELETE_ENTRIES);
		db.execSQL("DROP TABLE " + TABLE_UPDATE + ";");
        onCreate(db);
		
	}
	

}
